home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr42 / smixc111.zip / DETECT.C < prev    next >
C/C++ Source or Header  |  1995-02-15  |  2KB  |  62 lines

  1. /*      SMIXC is Copyright 1995 by Ethan Brodsky.  All rights reserved      */
  2.  
  3. /* ██ DETECT.C ████████████████████████████████████████████████████████████ */
  4.  
  5. #define TRUE  1
  6. #define FALSE 0
  7.  
  8. int detect_settings(int *baseio, int *irq, int *dma, int *dma16);
  9.   /* Detects sound card settings using BLASTER environment variable */
  10.   /* Parameters:                                                    */
  11.   /*   baseio    Sound card base IO address                         */
  12.   /*   irq       Sound card IRQ                                     */
  13.   /*   dma       Sound card 8-bit DMA channel                       */
  14.   /*   dma16     Sound card 16-bit DMA channel (0 if none)          */
  15.   /* Returns:                                                       */
  16.   /*   TRUE      Sound card settings detected successfully          */
  17.   /*   FALSE     Sound card settings could not be detected          */
  18.  
  19. /* ████████████████████████████████████████████████████████████████████████ */
  20.  
  21. #include <ctype.h>
  22. #include <dos.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25.  
  26. int get_setting(char *str, char id, int hex)
  27.   {
  28.     char temp[128];
  29.     char *endptr;
  30.  
  31.     strcpy(temp, str);
  32.     if (strchr(temp, id) != NULL)
  33.       {
  34.         strcpy(temp, strchr(temp, id)+1);          /* Cut off begining      */
  35.         if (strchr(temp, ' ') != NULL)
  36.           *(strchr(temp, ' ')) = '\0';             /* Cut off end           */
  37.  
  38.         if (hex) strcpy(temp, strcat("0x", temp)); /* Insert a "0x" for hex */
  39.  
  40.         return(strtoul(temp, &endptr, 0));
  41.       }
  42.     else
  43.       return(0);
  44.   }
  45.  
  46. int detect_settings(int *baseio, int *irq, int *dma, int *dma16)
  47.   {
  48.     char blaster[128];
  49.  
  50.     strcpy(blaster, strupr(getenv("BLASTER")));
  51.  
  52.     *baseio  = get_setting(blaster, 'A', TRUE);   /* Hex     */
  53.     *irq     = get_setting(blaster, 'I', FALSE);  /* Decimal */
  54.     *dma     = get_setting(blaster, 'D', FALSE);  /* Decimal */
  55.     *dma16   = get_setting(blaster, 'H', FALSE);  /* Decimal */
  56.  
  57.     if (blaster == "") return(FALSE);
  58.     if (baseio  == 0)  return(FALSE);
  59.     if (irq     == 0)  return(FALSE);
  60.     if (dma     == 0)  return(FALSE);
  61.     return(TRUE);
  62.   }